//
//  ByPhysicalProductDetailVC.m
//  jinpuyiyuan_ios
//
//  Created by pro on 2017/12/14.
//  Copyright © 2017年 mc. All rights reserved.
//

#import "ByPhysicalProductDetailVC.h"

@interface ByPhysicalProductDetailVC ()
@property (nonatomic, strong) UIScrollView *scroll;
@end

@implementation ByPhysicalProductDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"产品详情";
    [self addLeftBackBarButtonItem];
    [self createViews];
}

#pragma mark - getter
- (UIScrollView *)scroll{
    if (!_scroll) {
        _scroll = [[UIScrollView alloc] init];
        [self.view addSubview:_scroll];
        [_scroll mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(0));
            make.right.equalTo(@(0));
            if (@available(iOS 11.0,*)) {
                make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
                make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-40);
            }else{
                make.top.equalTo(self.view.mas_top);
                make.bottom.equalTo(self.view.mas_bottom).offset(-40);
            }
        }];
        _scroll.bounces = NO;
        _scroll.showsHorizontalScrollIndicator = NO;
    }
    return _scroll;
}

#pragma mark -  create views
- (void)createViews{
    UIButton *sureBuyButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:sureBuyButton];
    [sureBuyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(0));
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 40));
        if (@available(iOS 11.0,*)) {
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
        }else{
            make.bottom.equalTo(self.view.mas_bottom);
        }
    }];
    // 测试数据
    NSString *title = @"标题标题标题";
    NSString *price = @"2374.00";
    NSString *origin_price = @"1273.00";
    // 图片
    UIImageView *img = [[UIImageView alloc] init];
    [self.scroll addSubview:img];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(0));
        make.top.equalTo(@(0));
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, SCREEN_WIDTH / 2));
    }];
    img.backgroundColor = BY_THEME_COLOR;
    
    // 标题
    UILabel *titleLabel = [[UILabel alloc] init];
    [self.scroll addSubview:titleLabel];
    CGFloat height = [title getRectOfStringWithSize:CGSizeMake(SCREEN_WIDTH - 20, MAXFLOAT) font:14].size.height;
    titleLabel.numberOfLines = 0;
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(10));
        make.top.equalTo(img.mas_bottom).offset(15);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 20, height));
    }];
    titleLabel.text = title;
    titleLabel.font = FONT(14);
    
    // 价格
    UILabel *priceLabel = [[UILabel alloc] init];
    [self.scroll addSubview:priceLabel];
    CGFloat width = [price getSizeOfString:14].width;
    [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(10));
        make.top.equalTo(titleLabel.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(width, 20));
    }];
    priceLabel.font = FONT(14);
    priceLabel.text = [NSString stringWithFormat:@"￥%@",price];
    priceLabel.textColor = BY_THEME_COLOR;
    
    // 原价
    UILabel *originLabel = [[UILabel alloc] init];
    [self.scroll addSubview:originLabel];
    [originLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(priceLabel.mas_right).offset(5);
        make.top.equalTo(priceLabel.mas_top);
        make.right.equalTo(@(0));
        make.height.equalTo(@(20));
    }];
    
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"￥%.2lf", [origin_price floatValue]]];
    [attr addAttribute:NSStrikethroughStyleAttributeName
                 value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle)
                 range:NSMakeRange(0, attr.length)];
    [attr addAttribute:NSFontAttributeName value:FONT(13) range:NSMakeRange(0, attr.length)];
    originLabel.attributedText = attr;
    
    // line
    UIView *line = [[UIView alloc] init];
    [self.scroll addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(0));
        make.bottom.equalTo(priceLabel.mas_bottom).offset(15);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 1));
    }];
    line.backgroundColor = [UIColor colorWithWhite:0.90 alpha:1];
    
    // 内容
    
}



@end
